import pygame
import random
import g

class npc():
    def __init__(self, x, y, color):
        self.rect = pygame.Rect(x, y, 20, 20)
        self.color = color
        self.vx = 0
        self.vy = 0
        self.ax = 0
        self.ay = 0
        self.a_max = .6
        self.v_max = 6

    def move(self):
        if self.rect.collidelist(g.map.geoms) != -1:
            self.rect.x += random.randint(-5,5)
            self.rect.y += random.randint(-5,5)
        else:
            self.ax = max(min(random.randint(-1, 1)+self.ax, self.a_max), -self.a_max)
            self.ay = max(min(random.randint(-1, 1)+self.ay, self.a_max), -self.a_max)
            self.vx = max(min(self.vx+self.ax, self.v_max), -self.v_max)
            self.vy = max(min(self.vy+self.ay, self.v_max), -self.v_max)
            if pygame.Rect(self.rect.x+self.vx, self.rect.y+self.vy, self.rect.w, self.rect.h).collidelist(g.map.geoms) == -1:
                self.rect.x += self.vx
                self.rect.y += self.vy
            else:
                self.vx = 0
                self.vy = 0